#ifndef EVENT_HUB_H
#define EVENT_HUB_H

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
#include "./event/event_queue.h"
#include "./event/event.h"
#include "./event/list.h"
#include "./mcuevent/mcu_event.h"

#ifdef __cplusplus
extern "C"  {
#endif

typedef  struct _event_hub
{
   // interface functions
    int (* start)(void *event_hub);
    int (* stop)(void *event_hub);
    int (* send_event)(void *event_hub, event_s *event);
    int (* send_event_with_response)(void *event_hub, event_s *event);
    
    // callback list
    list_s *listener;
    // event queue
    event_queue_s *event_q;
    // mcu proxy
    mcu_event_proxy_s *mcu_proxy;
    
    int running; // 1 indicate running, 0 need to exit
    
    // synchronization primitives
    pthread_mutex_t mutex;
    pthread_cond_t startable;
    
} event_hub_s;

int create_event_hub(event_hub_s **event_hub);
void destroy_event_hub(event_hub_s *event_hub);

void event_hub_register_callback(void *event_hub, event_callback_s *event_callback);

#ifdef __cplusplus
}
#endif

#endif	/* EVENT_HUB_H */
